<script lang="ts" setup>
	import {
		useRouter
	} from 'uni-mini-router'
	import {
		userStore
	} from '@/pinia';
	import {
		getCurrentInstance
	} from 'vue'
	const {
		proxy,
	} = getCurrentInstance()
	const userStoreInfo = userStore();
	let router = useRouter()
	let emits = defineEmits(['delete', 'zhiding'])
	const routerLink = (url, id, index) => {
		uni.$on('marketLike', (data) => {
			props.listData[index].like = data.like
			props.listData[index].likeNum = data.likeNum
			props.listData[index].collect = data.collect
			props.listData[index].collectNum = data.collectNum
			uni.$off('marketLike')
		})
		emits('delete')
		router.push({
			name: url,
			params: {
				id,
				data: JSON.stringify(props.screenObj)
			}
		})
		setTimeout(() => {
			props.listData[index].viewNum++
		}, 600)
	}
	let props = defineProps(['type', 'listData', 'screenObj'])
	const zhiding = (id, isTop) => {
		//查询我的卡
		proxy.$req('POST', proxy.$api.myZhidingkaQuery, {
			topType: 4,
			userId: userStoreInfo.userInfo.id,
			userType: userStoreInfo.userFlag
		}).then((res) => {
			if (!res.success) {
				router.push({
					name: "zhidingPay",
					params: {
						id: 4
					}
				})
			} else if (isTop == 1) {
				//置顶 
				router.push({
					name: "zhidingPay",
					params: {
						id: 4
					}
				})
			} else {
				emits('delete')
				proxy.$req('POST', proxy.$api.yingxiaoUp, {
					id,
				}).then((res) => {
					uni.$u.toast(res.message)
					if (res.success) {
						uni.$emit('deleteRefash')
					} else {
						uni.$off('deleteRefash')
					}
				})
			}
		})
	}
	const likeAndCollect = (type1, type2, id, index) => {
		proxy.$req('POST', proxy.$api.likeAndCollect, {
			id: id,
			moduleType: 5,
			operateType: type1,
			updateType: type2,
			userId: userStoreInfo.userInfo.id
		}).then((res) => {
			console.log(res);
			uni.showToast({
				title: res.message,
				icon: 'none'
			})
			if (type1 == 0 && type2 == 'like') {
				props.listData[index].like = 1
				props.listData[index].likeNum++
			} else if (type1 == 0 && type2 == 'unlike') {
				props.listData[index].like = null
				props.listData[index].likeNum--
			} else if (type1 == 1 && type2 == 'collect') {
				props.listData[index].collect = 1
				props.listData[index].collectNum++
			} else if (type1 == 1 && type2 == 'uncollect') {
				props.listData[index].collect = null
				props.listData[index].collectNum--
			}
		})
	}
</script>
<template>
	<view class="markCon" @click="routerLink(props.type,item.id,index)" v-for="(item,index) in props.listData"
		:key="index">
		<image class="mcLeft" :src="JSON.parse(item.coverImages)[0].url" mode=""></image>
		<view class="mcRight">
			<view class="mcr1 u-line-2">
				{{ item.title }}
			</view>
			<view class="mcr3">
				<view class="" @click.stop="likeAndCollect(0,item.like==null?'like':'unlike',item.id,index)">
					<u-icon :name="item.like?'thumb-up-fill':'thumb-up'" :color="item.like?'#CB645E':'' "></u-icon>
					<text :style="{color:item.like?'#CB645E':''}">{{ item.likeNum >0?item.likeNum:0}}</text>
				</view>
				<view class="" @click.stop="likeAndCollect(1,item.collect==null?'collect':'uncollect',item.id,index)">
					<u-icon :name="item.collect?'heart-fill':'heart' " :color="item.collect?'#CB645E':'' "></u-icon>
					<text :style="{color:item.collect?'#CB645E':''}">{{ item.collectNum>0?item.collectNum:0 }}</text>
				</view>
				<view class="">
					<u-icon name="eye"></u-icon>
					<text>{{ item.viewNum }}</text>
				</view>
			</view>
			<view class="mcr2">
				<view class="zanshi r-flex-center-center" @click.stop="zhiding(item.id,item.isTop)">
					<view class="" v-if="!item.isTop">
						<u-icon name="arrow-upward" color="#fff" size="40rpx"></u-icon>
					</view>
					<text v-else style="font-size: 24rpx;color: #fff;">置顶中</text>
				</view>
				<!-- <view class="zanshi r-flex-center-center">
					<u-icon name="edit-pen-fill" color="#fff" size="40rpx"></u-icon>
				</view> -->
				<!-- <image src="../../static/logo.png" mode="" @click="routerLink('gysAddMarket',item.id)"></image>
				<image src="../../static/logo.png" mode=""></image> -->
			</view>
		</view>
	</view>
</template>
<style lang="scss">
	.markCon {
		width: calc(100% - 48rpx);
		height: 216rpx;
		padding: 24rpx;
		background-color: #fff;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
		border-radius: 24rpx;
		border: 2rpx solid #FFFFFF;
		margin: 20rpx auto;
		display: flex;
		align-items: center;
		justify-content: flex-start;

		.mcLeft {
			width: 176rpx;
			height: 200rpx;
			border-radius: 6rpx;
			margin-right: 20rpx;
		}

		.mcRight {
			width: 430rpx;
			height: 200rpx;

			.mcr1 {
				width: 100%;
				height: 70rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.85);
			}

			.mcr2 {
				display: flex;
				justify-content: flex-end;
				height: 50rpx;

				// image {
				// 	width: 50rpx;
				// 	height: 50rpx;
				// 	border-radius: 30rpx;
				// 	margin-left: 30rpx;
				// }
				.zanshi {
					width: 100rpx;
					height: 48rpx;
					background-color: #CB645E;
					border-radius: 6rpx;
					justify-content: center;
					margin-left: 16rpx;
				}
			}

			.mcr3 {
				width: 100%;
				height: 70rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				view {
					display: flex;
					align-items: center;

					text {
						font-size: 26rpx;
						margin-right: 15rpx;
					}
				}
			}
		}
	}
</style>